﻿/**********************************************************************
 * @file   FITKMesherDriverGmsh.h
 * @brief  Gmsh网格驱动器
 * @author liuzhonghua (liuzhonghuaszch@163.com)
 * @date   2024-10-15
 *********************************************************************/
#ifndef __FITK_MESHER_DRIVER_GMSH_H___
#define __FITK_MESHER_DRIVER_GMSH_H___

#include "FITK_Interface/FITKInterfaceMeshGen/FITKAbstractMesherDriver.h"
#include "FITK_Kernel/FITKCore/FITKThreadTask.h"

class TopoDS_Shape;
class QTimer;

namespace Interface
{
    class FITKAbstractRegionMeshSize;
}

namespace Core
{
    class FITKAbstractDataObject;
}

namespace Gmsh
{
    /**
     * @brief Gmsh网格驱动器
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date 2024-10-15
     */
    class FITKMesherDriverGmsh : public Interface::FITKAbstractMesherDriver
    {
        Q_OBJECT
    public:
        /**
         * @brief Construct a new FITKMesherDriverGmsh object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-15
         */
        explicit FITKMesherDriverGmsh();
        /**
         * @brief Destroy the FITKMesherDriverGmsh object
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-15
         */
        virtual ~FITKMesherDriverGmsh();
        /**
         * @brief 启动网格划分程序
         * @param[i]  info           附加信息
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-07-18
         */
        virtual void startMesher(QStringList info = QStringList()) override;
        /**
         * @brief 结束网格划分程序
         * @param[i]  info           附加信息
         * @author LiBaojun (libaojunqd@foxmail.com)
         * @date 2024-07-18
         */
        virtual void stopMesher(QStringList info = QStringList()) override;

    public slots:
        /**
         * @brief  通过定时器监听日志输出
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-21
         */
        void timerListenLogSolt();


    private:
        /**
         * @brief  定时器，用于定时打印Gmsh的输出信息
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-31
         */
        QTimer* _logListen{};
        /**
         * @brief  日志信息的打印历史记录
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-31
         */
        int _logIndex{ 0 };
    };
    /**
     * @brief  线程进行划分网格
     * @author liuzhonghua (liuzhonghuaszch@163.com)
     * @date   2024-10-21
     */
    class MeshGenerateGmshThread : public Core::FITKThreadTask
    {
        Q_OBJECT;
    public:
        MeshGenerateGmshThread() = default;
        ~MeshGenerateGmshThread();
        /**
         * @brief    运行
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-21
         */
        void run();
    signals:
        /**
         * @brief  网格生成开始信号
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-21
         */
        void meshGenerateStart();
        /**
         * @brief    网格生成结束信号
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-21
         */
        void meshGenerateEnd();


    protected:
        /**
         * @brief    软件中几何数据输入到gmsh里
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-31
         */
        bool gmshOpenGeometry();
        /**
         * @brief    开始生成
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-18
         */
        bool startGenerate();
        /**
         * @brief    Gmsh对进行几何处理
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-18
         */
        bool gmshGeometryProcess();
        /**
         * @brief    Gmsh网格区域加密
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-16
         */
        bool gmshRefinedMesh();
        /**
         * @brief    Gmsh网格生成算法配置-全局尺寸大小，算法
         * @return   bool
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-14
         */
        bool gmshMeshAlgorithmConfig();
        /**
         * @brief    添加box加密区域
         * @param[i] regionMesh
         * @return   int
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-18
         */
        int addGmshMeshFieldBox(Interface::FITKAbstractRegionMeshSize* regionMesh);
        /**
         * @brief    添加Cylinder加密区域
         * @param[i] regionMesh
         * @return   int
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-18
         */
        int addGmshMeshFieldCylinder(Interface::FITKAbstractRegionMeshSize* regionMesh);
        /**
         * @brief    添加Sphere加密区域
         * @param[i] regionMesh
         * @return   int
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-18
         */
        int addGmshMeshFieldSphere(Interface::FITKAbstractRegionMeshSize* regionMesh);
        /**
         * @brief    2D算法配置
         * @param[i] algorithm2D algorithm2D
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-14
         */
        void algorithm2dDisposition(int algorithm2D);
        /**
         * @brief    3D算法配置
         * @param[i] algorithm3D
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-14
         */
        void algorithm3dDisposition(int algorithm3D);
        /**
         * @brief    2D重组算法配置
         * @param[i] reAlgorithm2D
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-14
         */
        void reAlgorithm2dDisposition(int reAlgorithm2D);
        /**
         * @brief    细化算法
         * @param[i] subAlgorithm
         * @return   void
         * @author   liuzhonghua (liuzhonghuaszch@163.com)
         * @date     2024-10-14
         */
        void subdivisionAlgorithmDisposition(int subAlgorithm);

    public:
        /**
         * @brief  工作路径
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-10-21
         */
        QString _workDir{};
        /**
         * @brief  输入文件
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date   2024-11-28
         */
        QString _input{};
        /**
         * @brief 数据对象，用于提取网格数据
         * @author liuzhonghua (liuzhonghuaszch@163.com)
         * @date 2024-10-14
         */
        QHash<QString, Core::FITKAbstractDataObject*> _dataObject{};
    };
}


#endif
